﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Security;
public partial class Pages_Comment_SingleShow : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["pid"] == null)
            Response.Redirect("AllProduct.aspx");
    }
    protected void login_Click(object sender, EventArgs e)
    {
        
       // Pan.Common.MessageBox.Show(this, "好的");
        System.Web.UI.HtmlControls.HtmlInputText txtName = ((System.Web.UI.HtmlControls.HtmlInputText)lgvPanle.FindControl("uname"));
        System.Web.UI.HtmlControls.HtmlInputText txtPass = ((System.Web.UI.HtmlControls.HtmlInputText)lgvPanle.FindControl("upass"));
        
        if (txtName != null || txtPass!=null)
        {
            string strEmail = txtName.Value.Trim();
            string strPass = txtPass.Value;

            if (Membership.ValidateUser(strEmail, strPass))
            {

                MembershipUser userObj = Membership.GetUser(Context.User.Identity.Name);
                string[] roles = Roles.GetRolesForUser(strEmail);
                string userRoles = "";
                foreach (string item in roles)
                {
                    userRoles += item + ",";
                }
                DateTime loginTime = DateTime.Now.AddHours(2);
                FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, strEmail, DateTime.Now, loginTime, false, userRoles.TrimEnd(new char[] { ',' }), "/");
                string HashTicket = FormsAuthentication.Encrypt(Ticket);
                HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);
                Response.Cookies.Add(UserCookie);

                Response.Redirect(string.Format("{0}#status",Request.Url.ToString()));

            }
            else
            {
                Pan.Common.MessageBox.Show(this, "输入的帐号或密码有误，请重试!");
                //gjz
            }
        }
    }
}
